<template>
	<view>
		<!-- 切换诊所 -->
		<uv-modal ref="toggleClinicModal" title="切换诊所" showCancelButton confirmColor="#2c9c3c" @confirm="confirm">
			<uv-radio-group
				v-model="clinicValue" 
				activeColor="#2c9c3c"
				iconPlacement="right"
				placement="column"
				labelSize="15"
				borderBottom
				>
				<uv-radio v-for="item, index in clinicList" :key="index" :name="item._id" size='30' customStyle="margin-top: 15px">
					{{ item.clinic }}
					<view style="color: rgba(0, 0, 0, 0.4);font-size: 28rpx;">{{ item.address }}</view>
				</uv-radio>
			</uv-radio-group>
		</uv-modal>
	</view>
</template>

<script>
	export default {
		name:"toggleClinic",
		data() {
			return {
				clinicValue: "",
				clinicList: [],
			};
		},
		created() {
			this.userinfo = this.$store.state.userinfo
		},
		methods: {
			openModel() {
				this.clinicValue = this.userinfo.clinic._id
				this.clinicList = this.userinfo.clinic_data_all
				this.$refs.toggleClinicModal.open();
			},
			confirm() {
				for (let i = 0; i < this.userinfo.clinic_data_all.length; i++) {
					if ( this.clinicValue === this.userinfo.clinic_data_all[i]._id ) {
						this.userinfo.clinic = this.userinfo.clinic_data_all[i]
						this.$store.dispatch('set_userinfo', this.userinfo)
						
						var pages = '/pages/patient/patient'
						if (this.userinfo.types === 1) {
							pages = '/pages/medic/medic'
						} else if (this.userinfo.types === 0) {
							pages = '/pages/nurse/nurse'
						} else if (this.userinfo.types === 3) {
							this.userinfo = '/pages/visit/visit'
						}
						uni.reLaunch({
						    url: pages
						});
						
						break
					}
				}
			}
		}
	}
</script>

<style>

</style>